﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Serie_Counter.DataLayer;
using Serie_Counter.Presentatie;
using Serie_Counter.BusinissLayer;
using Serie_Counter.General;
using Serie_Counter.Presentatie.GuiHelpers;

namespace Serie_Counter.Presentatie

{
    /// <summary>
    /// Main form, contains the active series & top menu
    /// </summary>
    public partial class MainForm : Form
    {

        private BL_Manager manager;
        private UserControlHelper uCHelper;
        private ShowFormDel showFormDel;
        private updateForm updateForm;

        public UserControlHelper UCHelper
        {
            get
            {
                return uCHelper;
            }
        }

        public MainForm(BL_Manager manager, ShowFormDel showFormDel, updateForm updateForm)
        {
            InitializeComponent();

            this.manager = manager;
            this.showFormDel = showFormDel;
            this.updateForm = updateForm;

            uCHelper = new UserControlHelper(panelSeries,SelectedCollection.Active,manager,updateForm);
            uCHelper.placeUserControls();    
        }

        ~MainForm()
        {
            manager.saveCurrentContent();
        }
       

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            SerieControlForm aS = new SerieControlForm(manager);
            aS.ShowDialog();
            uCHelper.placeUserControls();
            
        }

        private void exportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog();
            saveFile.Filter = "xml Files (*.xml)|*.xml";
            saveFile.ShowDialog();
            if (saveFile.FileName != "")
            {
                manager.Export(saveFile.FileName);
            }
        }

        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();
            openFile.Filter = "xml Files (*.xml)|*.xml";
            openFile.ShowDialog();
            if (openFile.FileName != "")
            {
                manager.import(openFile.FileName);
            }

            uCHelper.placeUserControls();
        }        

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            manager.saveCurrentContent();
        }

        private void archiveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showFormDel(CallForm.Archived);
        }

        private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //SettingsForm settingsForm = new SettingsForm(manager.getSettings());
            //if (settingsForm.ShowDialog() == DialogResult.OK)
            //{
            //    manager.setSettings(settingsForm.Settings);
            //}
            showFormDel(CallForm.Settings);
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutForm about = new AboutForm();
            about.ShowDialog();
        }
    }
}
